﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace AlanAamy.Net.TemperatureConverter.Infrastructure.Converters
{
    [ValueConversion(typeof(object), typeof(string))]
    public class StringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value == null ? null :  value.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Decimal ret;
            return ((value != null && (string)value != String.Empty && Decimal.TryParse(value.ToString(), out ret)) ? ret : Decimal.MaxValue);

        }
    }
}
